home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 4_4.lha / 4_4 / 4_4.c < prev    next >
Text File  |  1993-08-08  |  824b  |  53 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / concatenate the listed files
  6. / onto the standard output
  7. include <stream.h>
  8.  
  9. / Copy a given file to cout.
  10. / Return 1 if there is an error.
  11. nt cat(char *file)
  12.  
  13.    filebuf f1;
  14.    if (f1.open(file, input) == 0)
  15. {
  16. cerr << "cannot open input file '" <<
  17.     file << "'\n";
  18. return 1;
  19. }
  20.  
  21.    istream from(&f1);
  22.    char ch;
  23.  
  24.    while (from.get(ch) && cout.put(ch))
  25. ;
  26.  
  27.    if (cout.bad())
  28. {
  29. cerr << "error on writing output\n";
  30. return 1;
  31. }
  32.  
  33.    else if (!from.eof())
  34. {
  35. cerr << "error on reading input file '" <<
  36.     file << "'\n";
  37. return 1;
  38. }
  39.  
  40.    return 0;
  41.  
  42.  
  43. nt main(int argc, char **argv)
  44.  
  45.    int err = 0;
  46.  
  47.    // loop through files
  48.    while (--argc > 0)
  49. err += cat(*++argv);
  50.  
  51.    return err;
  52.  
  53.